import { projectList } from '@/services'

export function formatDate(date) {
  var d = new Date(date),
          month = '' + (d.getMonth() + 1),
          day = '' + d.getDate(),
          year = d.getFullYear();
  if (month.length < 2) month = '0' + month;
  if (day.length < 2) day = '0' + day;
  return [year, month, day].join('-');
}

/**
 * 将秒化为小时数
 * @param {*} date 
 */
export function parseHour(date){
  return date ? (date/3600).toFixed(2) : 0
}

export function formatFullDate(time) {
    var date = new Date(time)
    var y = date.getFullYear();  
    var m = date.getMonth() + 1;  
    m = m < 10 ? ('0' + m) : m;  
    var d = date.getDate();  
    d = d < 10 ? ('0' + d) : d;  
    var h = date.getHours();
    h = h < 10 ? ('0' + h) : h; 
    var minute = date.getMinutes();  
    minute = minute < 10 ? ('0' + minute) : minute; 
    var second= date.getSeconds();  
    second = second < 10 ? ('0' + second) : second;  
    return y + '-' + m + '-' + d+' '+h+':'+minute+':'+ second;  
}

// 数值按万分割
export function formatNumber(num){
  let result = parseFloat(num);
  if(result<10000){
    return result.toFixed(2)
  }else{
    return (result/10000).toFixed(2) + '万'
  }
}

export const getChartColor = {
  '行驶': '#4DCB73',
  '驻车': '#FAD336',
  '泵送': '#F2637B',
  '转场': '#3AA0FF',
  '待料': '#36CBCB',
  '行驶里程': '#343a40',
  '泵送方量': '#F2637B',
  '油耗': '#FF8800',
  '待机': '#36CBCB'
}

export async function fetchProjectMap(){
  try {
    const data = await projectList();
    if(data.code == 200){
      sessionStorage.setItem('projectMap', JSON.stringify({ list: data.data }))
    }
  } catch (error) {
    console.log(error)
  }
}